package com.earth.quake.enhancement;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

public class CustomizedOverlay extends ItemizedOverlay<OverlayItem>{
	
	private ArrayList<OverlayItem> mapOverlays;
	private Context context;

	private Boolean markerTapped = false;
	GeoPoint tapPosition;
	OverlayItem item;
	public CustomizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		mapOverlays = new ArrayList<OverlayItem>();
         populate();
	}
		
	public CustomizedOverlay(Drawable defaultMarker, Context context) {
		this(defaultMarker);
		this.context = context;
	}
	@Override
	protected OverlayItem createItem(int i) {
		return mapOverlays.get(i);
	}
	@Override
	public int size() {
		return mapOverlays.size();
	}

	public boolean onTap(int index) {//GeoPoint geoPoint, MapView mapView) {
		markerTapped = true;
		item = mapOverlays.get(index);
		//Projection projection = mapView.getProjection();
       // tapPosition = projection.toPixels(geoPoint, null);
		tapPosition = item.getPoint();
		return true;
	} 
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		drawCircleDisplay(canvas, mapView, shadow);
	}

	private void drawCircleDisplay(Canvas canvas, MapView mapView, boolean shadow) {

	if(markerTapped){
		Projection projection = mapView.getProjection();
	
		int radius = 25;
		if (shadow) {
			// Create and setup your paint brush
		    Paint paint = new Paint();
		    paint.setARGB(255, 0, 255, 255);
		   // paint.setColor(0x30000000);
		    paint.setStyle(Style.FILL_AND_STROKE);
		    Point tapPoint = projection.toPixels(tapPosition, null);
			canvas.drawCircle((float)tapPoint.x, (float)tapPoint.y, radius, paint);
		}		
	}
	super.draw(canvas, mapView, shadow);
	
}

	public void addOverlay(OverlayItem overlay) {
		mapOverlays.add(overlay);
		this.populate();
	}
}

